import { Provide } from '@midwayjs/decorator';
import { BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { MenuEntity } from '../entity/menu';

/**
 * 导航菜单
 */
@Provide()
export class MenuService extends BaseService {
    @InjectEntityModel(MenuEntity)
    menuEntity: Repository<MenuEntity>;

    /**
     * 导航菜单
     */
    async getMenus() {
        try {
            const list = await this.menuEntity.find({
                where: {
                    status: 1
                },
                order: {
                    sort: 'DESC'
                }
            });
            return {
                success: true,
                message: '查询成功',
                data: list,
            }
        } catch (error) {
            throw new Error(error);
        }
    }
}
